//
//  ViewController.m
//  BBKit
//
//  Created by apple on 2019/6/28.
//  Copyright © 2019年 baobao. All rights reserved.
//

#import "ViewController.h"
#import "BBKit.h"

#import "UITableView+Regist.h"
#import "BBTableModel.h"


#import "TextTableController.h"
#import "IndicatorCellController.h"

@interface ViewController ()

@property(nonatomic,strong)  BBTableModel * cellModel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    UISwitch * ssich = [[UISwitch alloc] init];
//    ssich addTarget:self action:@selector(click) forControlEvents:(UIControlEvents)
   __weak __typeof(&*self)weakSelf = self;
    
     UITableView * tableview = self.view.addTableView(10).backgroundColor([UIColor whiteColor]).frame(self.view.bounds).view;
    
//    @weakify(self);
//    dispatch_async(dispatch_get_main_queue(), ^{
//         @strongify(self);
//    });

    //注册单元格
     RegisterTableViewCell(tableview, @"BBTableIndicatorCell");
    //表的数据源
    self.cellModel = [[BBTableModel alloc] initWithHostView:tableview];
    self.cellModel.headerHeight = 8;
    
    //表的分区数据源
    BBTableSectionModel * sectionModel1 = [BBTableSectionModel new];
    //单元格数据源
    BBCellModel * model1 = [BBCellModel new];
    //设置显示的单元格
    model1.cellName = @"BBTableIndicatorCell";
    //设置标题
    model1.title = @"TextCell";
    //设置左侧小图标
    model1.icon = @"bbcell_indecator_setting";
    
    BBCellModel * model2 = [BBCellModel new];
    model2.cellName = @"BBTableIndicatorCell";
    model2.title = @"IndicatorCell2";
    model2.icon = @"bbcell_indecator_setting";
    NSArray * rowArr1 = @[model1,model2];
    
    BBTableSectionModel * sectionModel2 = [BBTableSectionModel new];
    BBCellModel * model3 = [BBCellModel new];
    model3.cellName = @"BBTableIndicatorCell";
    model3.title = @"collectonView";
    
    BBCellModel * model4 = [BBCellModel new];
    model4.cellName = @"BBTableIndicatorCell";
    model4.title = @"IndicatorCell4";
    
    NSArray * rowArr2 = @[model3,model4];
    
    sectionModel1.sectionArray = rowArr1;
    sectionModel2.sectionArray = rowArr2;

    self.cellModel.rowArray = @[sectionModel1,sectionModel2];
    [tableview reloadData];
    
   
    self.cellModel.cellAction = ^(BBCellModel * _Nonnull model) {
        //cell点击事件
        if ([model.indexPath isEqual:[NSIndexPath indexPathForRow:0 inSection:0]])
        {
            [weakSelf.navigationController pushViewController:[TextTableController new] animated:YES];
        }
        else if ([model.indexPath isEqual:[NSIndexPath indexPathForRow:1 inSection:0]])
        {
            [weakSelf.navigationController pushViewController:[IndicatorCellController new] animated:YES];
        }
        
    };
   
    

}


//- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
////    BBCellModel * cellModel = self.dataArray[indexPath.row];
//    UITableViewCell <BBTableViewCellProtocol> * cell = [tableView dequeueReusableCellWithIdentifier:@"testCell" forIndexPath:indexPath];
//
//    [cell setDataModel:@"11"];
//    return cell;
//
//}
//
//- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//    return 1;
//}
//
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//    return 3;
//}

@end
